
const { ccclass, property } = cc._decorator;

@ccclass
export default class Loading extends cc.Component {

  @property(cc.Sprite)
  bar: cc.Sprite = null;


  onEnable() {
    cc.debug.setDisplayStats(false);
    cc.resources.loadDir("json", this._progressCallback.bind(this), this._completeCallback.bind(this));
  }

  

  private _progressCallback(completeCount, totalCount, res) {
    let p = completeCount / totalCount;
    this.bar.fillRange = p;
  }

  private _completeCallback(err, assets) {
    if (err) {
      cc.log(err);
      return;
    } else {

      this.bar.fillRange = 0;
      cc.tween(this.bar).to(1, { fillRange: 1 }).call(() => {
        cc.director.loadScene("index");
      }).start()
    }
  }
}
